Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Questions  >  Example 1:Consider array has 4 elements and a... Start Learning for Free
Example 1:
Consider array has 4 elements and a searching element 16.
A[4]= {10, 16, 22, 25} 
The number of iterations are required to search an element by using a binary search= T1
Example 2:
Consider array has 4 elements and a searching element 22.
A[4]= {10, 16, 22, 25} 
The number of iterations are required to search an element by using a binary search= T2
Note: Searching is successful.
Q.Which of the following statement are true?
  • a)
    T1 = T2
  • b)
    T1 < T2
  • c)
    T1 >T2
  • d)
    T2 < T1
Correct answer is option 'B'. Can you explain this answer?
Verified Answer
Example 1:Consider array has 4 elements and a searching element 16.A[4...
The correct answer is option 2.
Concept:
Binary Search:
A Binary Search is a sorting method used to find a specific member in a sorted array. Because binary search works only on sorted arrays, an array must be sorted before using binary search on it. As the number of iterations in the binary search reduces, it is a superior searching approach to the liner search technique.
Algorithm:
int binarySearch(int a[], int beg, int end, int K)    
{    
    int mid;    
    if(end >= beg)     
    {   mid = (beg + end)/2;    
        if(a[mid] == K)                 
            return mid+1;    
        else if(a[mid] < K) 
            return binarySearch(a, mid+1, end, K);      
        else   
            return binarySearch(a, beg, mid-1, K);            
    }    
    return -1;     
}   
Example 1:
The given data,
A[4]= {10, 16, 22, 25} 
Searching element= K= 16
beg= 0
end = 3
mid = 3/2 = 1
 if K with A[mid] and search is successful. 
Hence the number iterations are =1.
Example 2:
The given data,
A[4]= {10, 16, 22, 25} 
Searching element= K= 22
beg= 0
end = 3
mid = 3/2 = 1.
Compare 22 with A[1] is not found and K is greater than A[mid]. So  call binarySearch(a, 1+1, 3, 2); 
beg= 2
end = 3
mid = 5/2 = 2.
Compare 22 with A[2] is found.
Hence the number of iterations is = 2
Hence the correct answer is T1 < T2.
View all questions of this test
Most Upvoted Answer
Example 1:Consider array has 4 elements and a searching element 16.A[4...
Understanding Binary Search Iterations
Binary search is an efficient algorithm used to find an element in a sorted array. The number of iterations required to find an element can vary based on the position of the element being searched.
Example Analysis
- Array Elements: A[4] = {10, 16, 22, 25}
- Searching Element for Example 1: 16
- Searching Element for Example 2: 22
Iteration Details
- T1 (Searching for 16):
- Start with the entire array: indexes 0 to 3.
- Middle index = 1 (value = 16).
- Found in 1 iteration.
- T2 (Searching for 22):
- Start with the entire array: indexes 0 to 3.
- Middle index = 1 (value = 16).
- Since 22 > 16, search the right half (indexes 2 to 3).
- New middle index = 2 (value = 22).
- Found in 2 iterations.
Conclusion
- Comparison of Iterations:
- T1 (1 iteration) is less than T2 (2 iterations).
Thus, the statement T1 < /> is correct, making option b the true statement.
Summary of Options
- a) T1 = T2: False
- b) T1 < t2:="" />
- c) T1 > T2: False
- d) T2 < t1:="" />
Understanding the binary search algorithm's mechanics is crucial in determining how many iterations are needed based on the searched element's position.
Free Test
Community Answer
Example 1:Consider array has 4 elements and a searching element 16.A[4...
The correct answer is option 2.
Concept:
Binary Search:
A Binary Search is a sorting method used to find a specific member in a sorted array. Because binary search works only on sorted arrays, an array must be sorted before using binary search on it. As the number of iterations in the binary search reduces, it is a superior searching approach to the liner search technique.
Algorithm:
int binarySearch(int a[], int beg, int end, int K)    
{    
    int mid;    
    if(end >= beg)     
    {   mid = (beg + end)/2;    
        if(a[mid] == K)                 
            return mid+1;    
        else if(a[mid] < K) 
            return binarySearch(a, mid+1, end, K);      
        else   
            return binarySearch(a, beg, mid-1, K);            
    }    
    return -1;     
}   
Example 1:
The given data,
A[4]= {10, 16, 22, 25} 
Searching element= K= 16
beg= 0
end = 3
mid = 3/2 = 1
 if K with A[mid] and search is successful. 
Hence the number iterations are =1.
Example 2:
The given data,
A[4]= {10, 16, 22, 25} 
Searching element= K= 22
beg= 0
end = 3
mid = 3/2 = 1.
Compare 22 with A[1] is not found and K is greater than A[mid]. So  call binarySearch(a, 1+1, 3, 2); 
beg= 2
end = 3
mid = 5/2 = 2.
Compare 22 with A[2] is found.
Hence the number of iterations is = 2
Hence the correct answer is T1 < T2.
Explore Courses for Computer Science Engineering (CSE) exam

Similar Computer Science Engineering (CSE) Doubts

Question Description
Example 1:Consider array has 4 elements and a searching element 16.A[4]= {10, 16, 22, 25}The number of iterations are required to search an element by using a binary search= T1Example 2:Consider array has 4 elements and a searching element 22.A[4]= {10, 16, 22, 25}The number of iterations are required to search an element by using a binary search= T2Note: Searching is successful.Q.Which of the following statement are true?a)T1 = T2b)T1 < T2c)T1 >T2d)T2 < T1Correct answer is option 'B'. Can you explain this answer? for Computer Science Engineering (CSE) 2025 is part of Computer Science Engineering (CSE) preparation. The Question and answers have been prepared according to the Computer Science Engineering (CSE) exam syllabus. Information about Example 1:Consider array has 4 elements and a searching element 16.A[4]= {10, 16, 22, 25}The number of iterations are required to search an element by using a binary search= T1Example 2:Consider array has 4 elements and a searching element 22.A[4]= {10, 16, 22, 25}The number of iterations are required to search an element by using a binary search= T2Note: Searching is successful.Q.Which of the following statement are true?a)T1 = T2b)T1 < T2c)T1 >T2d)T2 < T1Correct answer is option 'B'. Can you explain this answer? covers all topics & solutions for Computer Science Engineering (CSE) 2025 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for Example 1:Consider array has 4 elements and a searching element 16.A[4]= {10, 16, 22, 25}The number of iterations are required to search an element by using a binary search= T1Example 2:Consider array has 4 elements and a searching element 22.A[4]= {10, 16, 22, 25}The number of iterations are required to search an element by using a binary search= T2Note: Searching is successful.Q.Which of the following statement are true?a)T1 = T2b)T1 < T2c)T1 >T2d)T2 < T1Correct answer is option 'B'. Can you explain this answer?.
Solutions for Example 1:Consider array has 4 elements and a searching element 16.A[4]= {10, 16, 22, 25}The number of iterations are required to search an element by using a binary search= T1Example 2:Consider array has 4 elements and a searching element 22.A[4]= {10, 16, 22, 25}The number of iterations are required to search an element by using a binary search= T2Note: Searching is successful.Q.Which of the following statement are true?a)T1 = T2b)T1 < T2c)T1 >T2d)T2 < T1Correct answer is option 'B'. Can you explain this answer? in English & in Hindi are available as part of our courses for Computer Science Engineering (CSE). Download more important topics, notes, lectures and mock test series for Computer Science Engineering (CSE) Exam by signing up for free.
Here you can find the meaning of Example 1:Consider array has 4 elements and a searching element 16.A[4]= {10, 16, 22, 25}The number of iterations are required to search an element by using a binary search= T1Example 2:Consider array has 4 elements and a searching element 22.A[4]= {10, 16, 22, 25}The number of iterations are required to search an element by using a binary search= T2Note: Searching is successful.Q.Which of the following statement are true?a)T1 = T2b)T1 < T2c)T1 >T2d)T2 < T1Correct answer is option 'B'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of Example 1:Consider array has 4 elements and a searching element 16.A[4]= {10, 16, 22, 25}The number of iterations are required to search an element by using a binary search= T1Example 2:Consider array has 4 elements and a searching element 22.A[4]= {10, 16, 22, 25}The number of iterations are required to search an element by using a binary search= T2Note: Searching is successful.Q.Which of the following statement are true?a)T1 = T2b)T1 < T2c)T1 >T2d)T2 < T1Correct answer is option 'B'. Can you explain this answer?, a detailed solution for Example 1:Consider array has 4 elements and a searching element 16.A[4]= {10, 16, 22, 25}The number of iterations are required to search an element by using a binary search= T1Example 2:Consider array has 4 elements and a searching element 22.A[4]= {10, 16, 22, 25}The number of iterations are required to search an element by using a binary search= T2Note: Searching is successful.Q.Which of the following statement are true?a)T1 = T2b)T1 < T2c)T1 >T2d)T2 < T1Correct answer is option 'B'. Can you explain this answer? has been provided alongside types of Example 1:Consider array has 4 elements and a searching element 16.A[4]= {10, 16, 22, 25}The number of iterations are required to search an element by using a binary search= T1Example 2:Consider array has 4 elements and a searching element 22.A[4]= {10, 16, 22, 25}The number of iterations are required to search an element by using a binary search= T2Note: Searching is successful.Q.Which of the following statement are true?a)T1 = T2b)T1 < T2c)T1 >T2d)T2 < T1Correct answer is option 'B'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice Example 1:Consider array has 4 elements and a searching element 16.A[4]= {10, 16, 22, 25}The number of iterations are required to search an element by using a binary search= T1Example 2:Consider array has 4 elements and a searching element 22.A[4]= {10, 16, 22, 25}The number of iterations are required to search an element by using a binary search= T2Note: Searching is successful.Q.Which of the following statement are true?a)T1 = T2b)T1 < T2c)T1 >T2d)T2 < T1Correct answer is option 'B'. Can you explain this answer? tests, examples and also practice Computer Science Engineering (CSE) tests.
Explore Courses for Computer Science Engineering (CSE) exam
Signup to solve all Doubts
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev